/**
* Created with CLion.
* User:Lenovo
* Date:2023-05-16
* Time:3:52
* Description:双向带头循环链表
*/

#include "List.h"

void TestList1()
{
    LTNode *pList = LTInit();
    LTPushBack(pList, 1);
    LTPushBack(pList, 2);
    LTPushBack(pList, 3);
    LTPushBack(pList, 4);

    LTPrint(pList);
    LTDestroy(pList);
    pList = NULL;
}

void TestList2()
{
    LTNode *pList = LTInit();
    LTPushFront(pList, 1);
    LTPushFront(pList, 2);
    LTPushFront(pList, 3);
    LTPushFront(pList, 4);

    LTPrint(pList);
    LTDestroy(pList);
    pList = NULL;
}

void TestList3()
{
    LTNode *pList = LTInit();
    LTPushFront(pList, 1);
    LTPushFront(pList, 2);
    LTPushFront(pList, 3);
    LTPushFront(pList, 4);

    LTPrint(pList);

    LTPopBack(pList);
    LTPrint(pList);
    LTPopBack(pList);
    LTPrint(pList);
    LTPopBack(pList);
    LTPrint(pList);
    LTPopBack(pList);
    LTPrint(pList);

    LTDestroy(pList);
    pList = NULL;
}

void TestList4()
{
    LTNode *pList = LTInit();
    LTPushFront(pList, 1);
    LTPushFront(pList, 2);
    LTPushFront(pList, 3);
    LTPushFront(pList, 4);

    LTPrint(pList);

    LTPopFront(pList);
    LTPrint(pList);
    LTPopFront(pList);
    LTPrint(pList);
    LTPopFront(pList);
    LTPrint(pList);
    LTPopFront(pList);
    LTPrint(pList);

    LTDestroy(pList);
    pList = NULL;
}

void TestList5()
{
    LTNode *pList = LTInit();
    LTPushFront(pList, 1);
    LTPushFront(pList, 2);
    LTPushFront(pList, 3);
    LTPushFront(pList, 4);

    LTPrint(LTFind(pList, 2));
    LTDestroy(pList);
    pList = NULL;
}

void TestList6()
{
    LTNode *pList = LTInit();
    LTPushFront(pList, 1);
    LTPushFront(pList, 2);
    LTPushFront(pList, 3);
    LTPushFront(pList, 4);

    LTInsertBefore(LTFind(pList, 2), 5);

    LTPrint(pList);
    LTDestroy(pList);
    pList = NULL;
}

void TestList7()
{
    LTNode *pList = LTInit();
    LTPushFront(pList, 1);
    LTPushFront(pList, 2);
    LTPushFront(pList, 3);
    LTPushFront(pList, 4);

    LTErase(LTFind(pList, 2));

    LTPrint(pList);
    LTDestroy(pList);
    pList = NULL;
}

void TestList8()
{
    LTNode *pList = LTInit();
    LTPushFront(pList, 1);
    LTPushFront(pList, 2);
    LTPushFront(pList, 3);
    LTPushFront(pList, 4);

    LTPrint(pList);
    LTDestroy(pList);
    pList = NULL;
}

int main()
{
    TestList1();
    TestList2();
    TestList3();
    TestList4();
    TestList5();
    TestList6();
    TestList7();
    TestList8();

    // 顺序表的 CPU 高速缓存命中率更高，链表则更低

    return 0;
}